//
//  DB.m
//  UI数据库
//
//  Created by dllo on 15/8/14.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "DB.h"
#import <sqlite3.h>
static sqlite3 *dbPoint = nil;

@implementation DB
//将bundle中得数据库拷贝到libray中进行操作

+ (sqlite3 *)addDB
{
    if (dbPoint) {
        return dbPoint;
    }
    
    NSFileManager *manage = [NSFileManager defaultManager];

    
    NSArray *arr = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    
    NSString *path = [[arr firstObject] stringByAppendingString:@"/ii.rdb"];
   
    NSLog(@"%@",path);
    if ([manage fileExistsAtPath:path] ) {
        
        
        
    }else{
    

    
        NSString *str = [[NSBundle mainBundle]pathForResource:@"City" ofType:@"rdb"];
        NSLog(@"%@",str);
        [manage copyItemAtPath:str toPath:path error:nil];
   
    }
    sqlite3_open([path UTF8String], &dbPoint);
    return dbPoint;
}
//+ (sqlite3 *)addCollect
//{
//    if (dbPoint) {
//        return dbPoint;
//    }
//    
//    NSFileManager *manage = [NSFileManager defaultManager];
//    
//    
//    NSArray *arr = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
//    
//    NSString *path = [[arr firstObject] stringByAppendingString:@"/ii.rdb"];
//    
//    NSLog(@"%@",path);
//    if ([manage fileExistsAtPath:path] ) {
//        
//        
//        
//    }else{
//        
//        
//        
//        NSString *str = [[NSBundle mainBundle]pathForResource:@"Collect" ofType:@"rdb"];
//        NSLog(@"%@",str);
//        [manage copyItemAtPath:str toPath:path error:nil];
//        
//    }
//    sqlite3_open([path UTF8String], &dbPoint);
//    return dbPoint;
//}

+ (void)dbClose
{
    
    
    sqlite3_close(dbPoint);
    
    
}







@end
